(ns use-fx-clj.freactive.rx
  (:require [fx-clj.core :as fx]
            [freactive.core :as f]
            [clojure.core.async :refer [go-loop chan <!]])
  (:import (javafx.application Platform)))

(def s0 (f/atom {:a {:b 0}}))
(add-watch s0 :kkk
  (fn [_ _ _ new]
    (println new)))

(def s1 (f/cursor s0 [:a :b]))
(def s (f/rx (str (* @s1 10))))

(defn create-view []
  (let [click-ch (chan)
        btn (fx/button :#my-btn {:on-action click-ch
                                 :text      "Next"})
        txt (fx/text s)
        view (fx/v-box txt btn)]
    (go-loop []
      (<! click-ch)
      (swap! s1 inc)
      (recur))
    view))

(Platform/setImplicitExit true)
(fx/sandbox #'create-view)
